Namespace("sketch.framework");

(function(fwk) {
    fwk.DropVisualization = klass(fwk.UIElement, (function() {
        var onDraggingElement = function(event){
            if(event.target != null){
                this._dropData = event.target.getDropData({x:event.mouseX, y:event.mouseY}, event.element);
            }else{
                this._dropData = null;
            }
        };

        var onStopDragging = function(event){
            this._dropData = null;
            this.invalidate();
        };

        var parentChanged = function(event){
            this.bindToSize(event.newValue.sizeProperties());
            var view = event.newValue.view();
            view.draggingEvent.bind(new EventHandler(this, onDraggingElement));
            view.stopDraggingEvent.bind(new EventHandler(this, onStopDragging));
        };
        return {
            __type__:'framework.DropVisualization',
            _constructor:function() {
                this.properties.bind("parent", new EventHandler(this, parentChanged));
                this._dropData = null;
                this.canSelect(false);
            },
            drawSelf:function(context){
                var data = this._dropData;
                if(data){
                    context.save();
                    context.strokeLine(data.x1, data.y1, data.x2, data.y2, "red", 2);
                    context.restore();
                }
            }
        };
    })());
})(sketch.framework);